n=int(input())
if 999<n<10000:
   k=0
   k1=0
   k2=0
   k3=0
   k4=0
   k5=0
   k6=0
   k7=0
   k8=0
   k9=0
   for i in range(2, n):
     if n%i==0:
       k+=1
   if k==0:
     print(n)
   else:
     n1=n%1000
     n2=n//10
     for i in range(2, n1):
       if n1%i==0:
         k1+=1
     for i in range(2, n2):
       if n2%i==0:
         k2+=1
     if k1==0 and k2!=0:
       print(n1)
     elif k1!=0 and k2==0:
       print(n2)
     elif k1==0 and k2==0:
       if n1>=n2:
         print(n1)
       else:
         print(n2)
     else:
       n3=n2//10
       n4=n2%100
       n5=n1%100
       for i in range(2, n3):
         if n3%i==0:
           k3+=1
       for i in range(2, n4):
         if n4%i==0:
           k4+=1
       for i in range(2, n5):
         if n5%i==0:
           k5+=1
       if k3==0 and k4!=0 and k5!=0:
         print(n3)
       elif k3!=0 and k4==0 and k5!=0:
         print(n4)
       elif k3!=0 and k4!=0 and k5==0:
         print(n5)
       elif  k3==0 and  k4==0 and k5!=0:
          if n3>n4:
             print(n3)
          else:
             print(n4)
       elif  k3!=0 and  k4==0 and k5==0:
          if n5>n4:
             print(n5)
          else:
             print(n4)
       elif  k3==0 and  k4!=0 and k5==0:
          if n5>n3:
             print(n5)
          else:
             print(n3)
       elif  k3==0 and  k4==0 and k5==0:
          if n5>=n4 and n5>=n3:
             print(n5)
          elif n3>=n4 and n3>=n5:
             print(n3)
          else:
             print(n4)
       else:
         n6=n//1000
         n7=n4//10
         n8=n4%10
         n9=n5%10
         for i in range(0,n6):
             if n6%i==0:
                k6+=1
         for i in range(2, n7):
           if n7%i==0:
             k7+=1
         for i in range(2, n8):
           if n8%i==0:
             k8+=1
         for i in range(2, n9):
           if n9%i==0:
             k9+=1
           if k6==0 and k7!=0 and k8!=0 and k9!=0:
             print(n6)
           elif k6!=0 and k7==0 and k8!=0 and k9!=0:
             print(n7)
           elif k6!=0 and k7!=0 and k8==0 and k9!=0:
             print(n8)
           elif k6!=0 and k7!=0 and k8!=0 and k9==0:
             print(n9)
           else:
              print(0)
else:
  print(0)
